<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

			
	function __construct()
	{
		parent::__construct();
		$this->load->model('login_model','',TRUE);
			
	}
	
	function index(){
		
		
		$this->load->view('login');
		
	}
	
	function chk_login()
	{
				
			
	$this->form_validation->set_rules('username', 'User Name', 'required');
	$this->form_validation->set_rules('password', 'Password', 'required');
											
			if ($this->form_validation->run() == FALSE) 
			{
				//$data['username']=$this->input->post('username');
				//$data['password']=$this->input->post('password');
				$this->load->view('login');
			
			}else{	
		
					//$main_admins=$this->admin_model->get_log_main_admins();
					$user_type= $this->login_model->admin_login();
					if($user_type)
					{
					
					$data = array(
					'username'=> $this->input->post('username'),
					'user_id'=>$user_type,
						'is_logged_in' => true
						);
					
					$this->session->set_userdata($data);
					redirect('dashboard',$data);
											
					}else{
						
						$data['errorlog']='Oops sorry! wrong username or password!';				
						$data['username']=$this->input->post('username');
						$data['password']=$this->input->post('password');
						$this->load->view('login',$data);
				
					}
	
		
		}
	}
	
	

	
	
}

?>